#!/bin/sh

# ApolloOS Build Script for Apps (Linux)
# Copyright (C) 2008 ApolloOS Developers
# For Terms see gpl.txt and license.txt

# These are some code samples for compiling programs from the app directory
# They are not used here as they are expected in binary form, but in case 
# you choose to use them... Just make sure you uncomment the relevant line in
# the loop-back mount routine in 'linbuild.sh'

# Assembling app source written in assembly (depending on extension)
echo '> Assembling Apps Written in Assembly...'
cd app
for i in *.asm
do
	nasm -f bin $i -o `basename $i .asm`.bin || exit
done

for i in *.s
do
	nasm -f elf $i -o `basename $i .asm`.bin || exit
done

cd ..

# Assembling app source written in C - Note: I haven't tried this yet!!!
# Make sure your included files are located in app/include and not src/include!
# link.ld (as used in the kernel) must also be present
echo '> Assembling Apps written in C... (Unsupported)'
cd app
for i in *.c
do
	gcc -Wall -O -fstrength-reduce -fomit-frame-pointer -finline-functions -nostdinc -fno-builtin -fleading-underscore -I./include -o 'basename $i .c'.o $i  || exit
	ld -T link.ld -o 'basename $i .c'.bin $i
done

cd ..

echo '> Starting Cleanup...'
cd app
rm *.o
cd ..

echo '> App Builds Complete!'